//
//  AudioMigration.swift
//  hello
//
//  Created by 赵康 on 2024/11/11.
//

import Fluent

extension Audio {
	struct Migration: AsyncMigration {
		var name: String { "AudioMigration" }
		
		func prepare(on database: any Database) async throws {
			try await database.schema(Audio.schema)
				.id()
				.field(Audio.FieldKeys.title, .string, .required)
				.field(Audio.FieldKeys.description, .sql(.text))
				.field(Audio.FieldKeys.duration, .double, .required)
				.field(Audio.FieldKeys.cover, .string)
				.field(Audio.FieldKeys.author, .string)
				.field(Audio.FieldKeys.url, .string, .required)
				.field(Audio.FieldKeys.size, .double, .required)
				
				.field(Audio.FieldKeys.album, .uuid, .references(Album.schema, .id))
				
				.field(Audio.FieldKeys.createdAt, .datetime, .required)
				.field(Audio.FieldKeys.updatedAt, .datetime, .required)
				.field(Audio.FieldKeys.isDeleted, .bool, .required, .custom("DEFAULT FALSE"))
				.create()
		}
		func revert(on database: any Database) async throws {
			try await database.schema(Audio.schema).delete()
		}
	}
}
